package servlet;

import javax.servlet.* ;
import javabean.Factory;
import javabean.tips.Tips;

public class SendTipsServlet extends BaseServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8538076142868886263L;
	
	public void service() throws Exception{
		//获取表单提交的值
		String uid = (String) getSession().getAttribute("uid") ;
		if(uid!=null){
			String bid1 = request.getParameter("bid") ;
			if(bid1!=null && !"".equals(bid1)){
				String ttitle = request.getParameter("ttitle") ;
				String tcontents = request.getParameter("tcontents") ;
				String receiver = request.getParameter("receiver");
				String type1 = request.getParameter("type");
				if("".equals(bid1) || bid1==null){
					bid1 = "0" ;
				}
				if("".equals(type1) || type1==null){
					type1 = "0";
				}
				long bid = Long.parseLong(bid1) ;
				int type = Integer.parseInt(type1);
				//将提交的值赋给tips对象
				Tips tips = new Tips() ;
				tips.setBid(bid) ;
				tips.setTTiTle(ttitle) ;
				tips.setTconTenTs(tcontents) ;
				tips.setSender(uid) ;
				tips.setReceiver(receiver) ;
				tips.setType(type);
				java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String NowTime = dateFormatter.format(new java.util.Date());
				tips.setTime(NowTime) ;
				try{
					if(Factory.getTipsDAOInstance().insert(tips)){
						response.getWriter().write("{\"isLogin\":true,\"success\":true,\"msg\":\"发送成功\"}");
					}else{
						response.getWriter().write("{\"isLogin\":true,\"success\":false,\"msg\":\"发送失败\"}");
					}
				}
				catch(Exception e){
				}
			}
		}
	}
}
